import com.baichang.framework.utils.MD5Util;
import com.baichang.taoshunda.utils.UserPushMsgUtil;

import java.math.BigDecimal;
import java.security.MessageDigest;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Created by ${wushenglu} on 17/08/26.
 */
public class test {
    public static void main(String[] args) {
//        for (int i=0;i<100;i++){
//            System.out.println("第"+(i+1)+"次"+getRedpacketBanlance(28.2));
//
//        }
        double bili = BigDecimal.valueOf(69).divide(BigDecimal.valueOf(164), 2, BigDecimal.ROUND_DOWN).doubleValue();
        double returnMoney = BigDecimal.valueOf(32.8).multiply(BigDecimal.valueOf(bili)).doubleValue();
        System.out.println("returnMoney=======================>" + returnMoney);
        System.out.println(BigDecimal.valueOf(5).divide(BigDecimal.valueOf(100), BigDecimal.ROUND_CEILING
                , 2));

//        System.out.println(MD5Util.md5("123456"));
//        System.out.println(MD5Util.string2MD5("2437531c310b7a05a35511f5f47d32d0"));
//        String s = new String("2437531c310b7a05a35511f5f47d32d0");
//        System.out.println("原始：" + s);
//        System.out.println("MD5后：" + string2MD5(s));
//        System.out.println("加密的：" + convertMD5(s));
//        System.out.println("解密的：" + convertMD5(convertMD5(s)));
//        System.out.println(getRed(5, 0.06, 0.01));
//
//        UserPushMsgUtil.reminderOrderPushByOrderStateToBusiness(1, 1, "15806692503", "4444", 1);
    }

    public static String string2MD5(String inStr) {
        MessageDigest md5 = null;
        try {
            md5 = MessageDigest.getInstance("MD5");
        } catch (Exception e) {
            System.out.println(e.toString());
            e.printStackTrace();
            return "";
        }
        char[] charArray = inStr.toCharArray();
        byte[] byteArray = new byte[charArray.length];
        for (int i = 0; i < charArray.length; i++)
            byteArray[i] = (byte) charArray[i];
        byte[] md5Bytes = md5.digest(byteArray);
        StringBuffer hexValue = new StringBuffer();
        for (int i = 0; i < md5Bytes.length; i++) {
            int val = ((int) md5Bytes[i]) & 0xff;
            if (val < 16)
                hexValue.append("0");
            hexValue.append(Integer.toHexString(val));
        }
        return hexValue.toString();
    }

    /**
     * 加密解密算法 执行一次加密，两次解密
     */
    public static String convertMD5(String inStr) {
        char[] a = inStr.toCharArray();
        for (int i = 0; i < a.length; i++) {
            a[i] = (char) (a[i] ^ 't');
        }
        String s = new String(a);
        return s;
    }

    public static double getRedpacketBanlance(double args) {
        int args2 = (int) args / 10 + 1;
        double args3 = args2 * 10;
        double start = (double) args3 / 1000;
        double end = start * 5;
        DecimalFormat df = new DecimalFormat("#.00");
        return Double.valueOf(df.format(Math.random() * (end - start) + start));
    }

    public static List getRed(int number, double total, double min) {
        //红包数
        //int number = 300;
        //红包总额
        // float total = 500;
        double money;
        //最小红包
        //double min = 0.48;
        double max;
        int i = 1;
        List math = new ArrayList();
        DecimalFormat df = new DecimalFormat("###.##");
        while (i < number) {
            //保证即使一个红包是最大的了,后面剩下的红包,每个红包也不会小于最小值
            max = total - min * (number - i);
            int k = (int) (number - i) / 2;
            //保证最后两个人拿的红包不超出剩余红包
            if (number - i <= 2) {
                k = number - i;
            }
            //最大的红包限定的平均线上下
            max = max / k;
            //保证每个红包大于最小值,又不会大于最大值
            money = (int) (min * 100 + Math.random() * (max * 100 - min * 100 + 1));
            money = (float) money / 100;
            //保留两位小数
            money = Double.parseDouble(df.format(money));
            total = (int) (total * 100 - money * 100);
            total = total / 100;
            math.add(money);
            System.out.println("第" + i + "个人拿到" + money + "剩下" + total);
            i++;
            //最后一个人拿走剩下的红包
            if (i == number) {
                math.add(total);
                System.out.println("第" + i + "个人拿到" + total + "剩下0");
            }
        }
        //取数组中最大的一个值的索引
        System.out.println("本轮发红包中第" + (math.indexOf(Collections.max(math)) + 1) + "个人手气最佳");
        return math;
    }
}
